﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

// 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“ServiceOutInterface”。
public class ServiceOutInterface : IServiceOutInterface
{

    private string ConnectionString = ConfigurationManager.AppSettings["DBLink"];

    private Dbcom cm = new Dbcom();
    public void DoWork()
    {
    }

    /// <summary>
    /// 病人Id
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public string getInpatientJsonById(string id)
    {
        try
        {
            string sql = "select t.id,t.patient_name,t.gender_code,t.birthday,t.card_id,t.agestr,t.sick_doctor_name,t.in_doctor_name from t_in_patient t where rownum<50 ";
            if (id != "")
            {
                sql = sql + " and id=" + id + "";
            }
            DataSet ds = Dbcom.GetDataSet(sql);

            //生成json数据
            string jsonstr = "[";
            string str = "";
            string strinpatient = "";
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                str = "{\"patient\":" +
                      "{\"id\":\"" + ds.Tables[0].Rows[i]["id"].ToString() +
                        "\",\"patient_name\":\"" + ds.Tables[0].Rows[i]["patient_name"].ToString() +
                        "\",\"gender_code\":\"" + ds.Tables[0].Rows[i]["gender_code"].ToString() +

                        "\",\"birthday\":\"" + ds.Tables[0].Rows[i]["birthday"].ToString() +
                        "\",\"card_id\":\"" + ds.Tables[0].Rows[i]["card_id"].ToString() +
                        "\",\"agestr\":\"" + ds.Tables[0].Rows[i]["agestr"].ToString() +
                         "\",\"sick_doctor_name\":\"" + ds.Tables[0].Rows[i]["sick_doctor_name"].ToString() +
                        "\",\"in_doctor_name\":\"" + ds.Tables[0].Rows[i]["in_doctor_name"].ToString() + "\"}}";
                if (strinpatient == "")
                {
                    strinpatient = str;
                }
                else
                {
                    strinpatient = strinpatient + "," + str;
                }
            }
            jsonstr = "[" + strinpatient + "]";
            return jsonstr;
        }
        catch(Exception ex)
        {
            return ex.Message;
        }

    }
}
